import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index'

Vue.use(VueRouter)

export const commonRouters = [
  {
    path: '/login',
    hidden: true, // 不在slider显示
    component: () =>
      import('@/views/login/index')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'Home',
    hidden: true,
    children: [{
      path: 'home',
      component: () =>
        import('@/views/Home')
    }]
  }
]

export const asyncRouters = [
  {
    path: '/home',
    hidden: false,
    component: Layout,
    meta: { title: 'Home', icon: 'el-icon-menu' }
  },
  {
    path: '/show',
    component: Layout,
    name: 'Show',
    hidden: false,
    redirect: '/show/menu',
    meta: { title: 'Show', icon: 'el-icon-menu' },
    children: [
      {
        path: 'menu',
        name: "menu",
        hidden: false,
        component: () =>
          import('@/views/Menu'),
        meta: { title: 'menu'}
      },
      {
        path: 'about',
        name: "about",
        hidden: false,
        component: () =>
          import('@/views/About'),
        meta: { title: 'about'}
      }
    ]
  },
  {
    path: '/ws',
    component: Layout,
    name: 'Ws',
    hidden: false,
    redirect: '/ws/chat',
    meta: { title: 'Ws', icon: 'el-icon-menu' },
    children: [
      {
        path: 'chat',
        name: "chat",
        hidden: false,
        component: () =>
          import('@/views/ws/index'),
        meta: { title: 'ws聊天室'}
      }
    ]
  },
  {
    path: '/chat',
    component: Layout,
    name: 'chat',
    hidden: false,
    redirect: '/chat/chat',
    meta: { title: 'Chat', icon: 'el-icon-menu' },
    children: [
      {
        path: 'chat',
        name: "chat",
        hidden: false,
        component: () =>
          import('@/views/chat/index'),
        meta: { title: 'ws聊天室'}
      }
    ]
  }
]

const createRouter = () => new VueRouter({
  mode: 'history',
  routes: commonRouters.concat(asyncRouters)
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}


export default router
